﻿#include "Piranha.h"
#include "ResourceManager.h"
#include <d3dx9.h>

Piranha::Piranha(int id,float x, float y, int type, int state)
{
	_sprite = new Sprite(_spriteHandler, ResourceManager::GetInstance()->GetTexture(ResourceManager::GetInstance()->TextureName.Piranha),150, 0);
	_id = id;
	_x = x +32/2;
	_y = y -32;
	_type = type;
	_width = _sprite->getTexture()->getWidth();
	_height = _sprite->getTexture()->getHeight();
	_state = state;
	_yPre = y - 64;
	_vy = 0.05;
	_timeStop = 0;
}

Piranha::~Piranha(void)
{

}

void Piranha::Update(list<Object *> *_list, float time)
{
	switch(_state)
	{
	case IS_IDLE:
		_timeStop += time;
		if (_timeStop > 1000)
		{
			_timeStop = 0;
			changeState(IS_ACTIVING);
		}
		
		break;
	case IS_ACTIVING:
		_sprite->SetFrame(0,2);

		_y += _vy * time ;
		
		if((_vy > 0) && (_y > _yPre + 64))				//Tới mức giới hạn
		{
			_vy = -_vy;

		}
		if((_vy < 0 && _y < _yPre))				//Tới mức giới hạn
		{
			changeState(IS_IDLE);

		}

		break;
	 
	}
	_sprite->Update(time);
	
}


void Piranha:: Render(int vpX, int vpY)
{
	if (this->_state == IS_ACTIVING)
	 {
		_sprite->Render(_x, _y, vpX, vpY);
		 
	 }
	
}

void Piranha::changeState(int state)
{
	_state = state;
	switch(_state)
	{
	case IS_IDLE:
		_timeStop = 0;
		break;
	case IS_ACTIVING:
		_vy = 0.05;
		break;
	case IS_REMOVE:
		break;
	}
}
OBJECT_TYPE Piranha::getObjectType()
{
	return OBJECT_ENEMY;
}